package com.chen10.cattle.controller;

import com.chen10.cattle.ai.model.AiMoveRequest;
import com.chen10.cattle.ai.model.AiMoveResponse;
import com.chen10.cattle.common.exception.BusinessException;
import com.chen10.cattle.common.protocal.ResponseResult;
import com.chen10.cattle.common.protocal.ResponseVO;
import com.chen10.cattle.service.AiFightService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/ai")
@Slf4j
public class AiFightController {
    @Resource
    private AiFightService aiFightService;

    /**
     * 玩家落子
     * @param aiMoveRequest 包含坐标和模式
     * @return
     */
    @PostMapping("/move")
    public ResponseVO<AiMoveResponse> move(@RequestBody AiMoveRequest aiMoveRequest) {
        try{
            return ResponseResult.success(aiFightService.move(aiMoveRequest));
        }catch (BusinessException e){
            return ResponseResult.error(e.getCode(), e.getMessage());
        }
    }
}
